import { dynamicStore } from "@store/dynamic"
import {get,patch} from "@utils/http"
import dayjs from "dayjs"
export const getDynamicBehavior=Behavior({
  methods:{
    getdynamic
  }
})
export const getDynamicMixin={
  getdynamic
}
async function getdynamic(){
  if(dynamicStore.last)return
  const {
    type,
    searchKey,
    size,
    page
  }=dynamicStore.dynamicForm
  const res=await get("/dynamics",{
     personal:false,
     type,
     page,
     size,
     tag:searchKey
   })
   const dynamicslist=[]
   for (let i = 0; i < res.content.length; i++) {
     const item = res.content[i];
     const dynamics={
       id:item[0],
       content:item[1],
       avatar:item[11],
       anonymous:item[4],
       provided:item[5],
       contact:item[9],
       name:item[10],
       commentnumber:item[13],
       lovenumber:item[6],
       sex:item[12],
       islove:item[14],
       userid:item[8],
       tags:[],
       srcs:[],
       diffTime:""
     }
     const tags=item[3].split(",").filter(item=>{
       return !!item.trim()
     })
     console.log(tags)
     dynamics.tags=tags
   dynamics.srcs=item[2].split(",")
   const createTime=dayjs(item[7])
   if(dayjs().diff(createTime,"year")){
     dynamics.diffTime=dayjs().diff(createTime,"year")+"年前"
   }else{
     if (dayjs().diff(createTime,"month")){
       dynamics.diffTime=dayjs().diff(createTime,"month")+"月前"
     }else{
       if(dayjs().diff(createTime,"day")){
         dynamics.diffTime=dayjs().diff(createTime,"day")+"日前"
       }else{
         if(dayjs().diff(createTime,"hour")){
           dynamics.diffTime=dayjs().diff(createTime,"hour")+"小时前"
         }else{
           if(dayjs().diff(createTime,"m")){
             dynamics.diffTime=dayjs().diff(createTime,"m")+'分钟前'
           }else{
             dynamics.diffTime="刚刚"
           }
         }
       }
     }
   }
     dynamicslist.push(dynamics)
   }
   this.addDynamicList(dynamicslist,res.last)
}